// vue前端接口模板
import request from '@/utils/request' // utils/request.js

import {
  Loading,
  Message
} from 'element-ui'



/**
 * 获取列表，并返回分页
 */
export async function getRequest(url) {
  //加载loading
  const loadingInstance = Loading.service({
    fullscreen: true,
    text: 'Loading',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)'
  });
  const res = await request({
    baseURL: process.env.VUE_APP_BASE_API,
    url: url,
    method: 'get',
  })
  //关闭loading
  loadingInstance.close();
  return res
}

/**
 * post
 */
  export async function  postRequest(url, data) {
  //加载loading
  // const  loadingInstance =  Loading.service({
  //   fullscreen: true,
  //   text: 'Loading',
  //   spinner: 'el-icon-loading',
  //   background: 'rgba(0, 0, 0, 0.7)'
  // });
  const res = await request({
    baseURL: process.env.VUE_APP_BASE_API,
    url: url,
    method: 'post',
    data
  })
  //关闭loading async await
  //  loadingInstance.close();
  return  res
}

/**
 * put
 */
 export async function putRequest(url, data) {
  //加载loading
  const loadingInstance = Loading.service({
    fullscreen: true,
    text: 'Loading',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)'
  });
  const res = await request({
    baseURL: process.env.VUE_APP_BASE_API,
    url: url,
    method: 'put',
    data
  })
  //关闭loading
  loadingInstance.close();
  return res
}

/**
 * put
 */
 export async function delRequest(url, data) {
  //加载loading
  const loadingInstance = Loading.service({
    fullscreen: true,
    text: 'Loading',
    spinner: 'el-icon-loading',
    background: 'rgba(0, 0, 0, 0.7)'
  });
  const res = await request({
    baseURL: process.env.VUE_APP_BASE_API,
    url: url,
    method: 'delete',
    data
  })
  //关闭loading
  loadingInstance.close();
  return res
}